package com.tengju.bff.interfaces.manage.crm.dealer.vo;

import com.tengju.bff.interfaces.shared.ColumnVO;
import com.tengju.bff.interfaces.shared.TableVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;

/**
 * @Auther: kezunfa
 * @Date: 2021/4/22 11:17
 * @Description: 
 */
@Data
@ApiModel(value = "DealerSupInfoVO", description = "经销商上级信息对象")
public class DealerSupInfoVO {

    @ApiModelProperty(value = "上级姓名")
    private String supUserName;

    @ApiModelProperty(value = "所属黑卡")
    private String asscHkName;

    @ApiModelProperty(value = "所属1星")
    private String blStar1Name;

    @ApiModelProperty(value = "所属2星")
    private String blStar2Name;

    @ApiModelProperty(value = "所属3星")
    private String blStar3Name;

    @ApiModelProperty(value = "所属4星")
    private String blStar4Name;

    @ApiModelProperty(value = "所属EC")
    private String blEcName;

    @ApiModelProperty(value = "所属Sec")
    private String blSecName;

    @ApiModelProperty(value = "所属俱乐部")
    private String blClubName;

    public static void splitObjectToTable(TableVO handleTable, String aggregationRowName) {
        if(handleTable == null || StringUtils.isBlank(aggregationRowName)){
            return;
        }

        handleTable.addColumn("supUserName", ColumnVO.of("supUserName", "上级姓名", false));
        handleTable.addColumn("asscHkName", ColumnVO.of("asscHkName", "所属黑卡", false));
        handleTable.addColumn("blStar1Name", ColumnVO.of("blStar1Name", "所属1星", false));
        handleTable.addColumn("blStar2Name", ColumnVO.of("blStar2Name", "所属2星", false));
        handleTable.addColumn("blStar3Name", ColumnVO.of("blStar3Name", "所属3星", false));
        handleTable.addColumn("blStar4Name", ColumnVO.of("blStar4Name", "所属4星", false));
        handleTable.addColumn("blEcName", ColumnVO.of("blEcName", "所属EC", false));
        handleTable.addColumn("blSecName", ColumnVO.of("blSecName", "所属Sec", false));
        handleTable.addColumn("blClubName", ColumnVO.of("blClubName", "所属俱乐部", false));

        handleTable.resolveRow(v -> {
            DealerSupInfoVO dealerSupInfo = (DealerSupInfoVO) v.get(aggregationRowName);
            v.put("supUserName", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getSupUserName).orElse(""));
            v.put("asscHkName", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getAsscHkName).orElse(""));
            v.put("blStar1Name", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getBlStar1Name).orElse(""));
            v.put("blStar2Name", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getBlStar2Name).orElse(""));
            v.put("blStar3Name", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getBlStar3Name).orElse(""));
            v.put("blStar4Name", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getBlStar4Name).orElse(""));
            v.put("blEcName", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getBlEcName).orElse(""));
            v.put("blSecName", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getBlSecName).orElse(""));
            v.put("blClubName", Optional.ofNullable(dealerSupInfo).map(DealerSupInfoVO::getBlClubName).orElse(""));
        });
    }

}
